<template>
  <div class="app-container">
    <el-form :inline="true" :model="queryParams" label-width="68px" ref="queryForm" size="small" v-show="showSearch">
      <el-form-item label="用户id" prop="userId">
        <el-input
          @keyup.enter.native="handleQuery"
          clearable
          placeholder="请输入用户id"
          v-model="queryParams.userId"
        />
      </el-form-item>
      <el-form-item label="订单单号" prop="orderNo">
        <el-input
          @keyup.enter.native="handleQuery"
          clearable
          placeholder="请输入订单单号"
          v-model="queryParams.orderNo"
        />
      </el-form-item>
      <el-form-item label="支付方式" prop="paymentWay">
        <el-input
          @keyup.enter.native="handleQuery"
          clearable
          placeholder="请输入支付方式"
          v-model="queryParams.paymentWay"
        />
      </el-form-item>
      <el-form-item label="是否支付" prop="isPay">
        <el-input
          @keyup.enter.native="handleQuery"
          clearable
          placeholder="请输入是否支付"
          v-model="queryParams.isPay"
        />
      </el-form-item>
      <el-form-item label="订单名" prop="name">
        <el-input
          @keyup.enter.native="handleQuery"
          clearable
          placeholder="请输入订单名"
          v-model="queryParams.name"
        />
      </el-form-item>
      <el-form-item label="运费金额" prop="freightPrice">
        <el-input
          @keyup.enter.native="handleQuery"
          clearable
          placeholder="请输入运费金额"
          v-model="queryParams.freightPrice"
        />
      </el-form-item>
      <el-form-item label="销售金额" prop="salesPrice">
        <el-input
          @keyup.enter.native="handleQuery"
          clearable
          placeholder="请输入销售金额"
          v-model="queryParams.salesPrice"
        />
      </el-form-item>
      <el-form-item label="支付金额" prop="paymentPrice">
        <el-input
          @keyup.enter.native="handleQuery"
          clearable
          placeholder="请输入支付金额"
          v-model="queryParams.paymentPrice"
        />
      </el-form-item>
      <el-form-item label="付款时间" prop="paymentTime">
        <el-date-picker clearable
                        placeholder="请选择付款时间"
                        type="date"
                        v-model="queryParams.paymentTime"
                        value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="发货时间" prop="deliveryTime">
        <el-date-picker clearable
                        placeholder="请选择发货时间"
                        type="date"
                        v-model="queryParams.deliveryTime"
                        value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="收货时间" prop="receiverTime">
        <el-date-picker clearable
                        placeholder="请选择收货时间"
                        type="date"
                        v-model="queryParams.receiverTime"
                        value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="成交时间" prop="closingTime">
        <el-date-picker clearable
                        placeholder="请选择成交时间"
                        type="date"
                        v-model="queryParams.closingTime"
                        value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="买家留言" prop="userMessage">
        <el-input
          @keyup.enter.native="handleQuery"
          clearable
          placeholder="请输入买家留言"
          v-model="queryParams.userMessage"
        />
      </el-form-item>
      <el-form-item label="支付交易ID" prop="transactionId">
        <el-input
          @keyup.enter.native="handleQuery"
          clearable
          placeholder="请输入支付交易ID"
          v-model="queryParams.transactionId"
        />
      </el-form-item>
      <el-form-item label="物流id" prop="logisticsId">
        <el-input
          @keyup.enter.native="handleQuery"
          clearable
          placeholder="请输入物流id"
          v-model="queryParams.logisticsId"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery" icon="el-icon-search" size="mini" type="primary">搜索</el-button>
        <el-button @click="resetQuery" icon="el-icon-refresh" size="mini">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          @click="handleAdd"
          icon="el-icon-plus"
          plain
          size="mini"
          type="primary"
          v-hasPermi="['weixin:info:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          :disabled="single"
          @click="handleUpdate"
          icon="el-icon-edit"
          plain
          size="mini"
          type="success"
          v-hasPermi="['weixin:info:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          :disabled="multiple"
          @click="handleDelete"
          icon="el-icon-delete"
          plain
          size="mini"
          type="danger"
          v-hasPermi="['weixin:info:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          @click="handleExport"
          icon="el-icon-download"
          plain
          size="mini"
          type="warning"
          v-hasPermi="['weixin:info:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :data="infoList" @selection-change="handleSelectionChange" v-loading="loading">
      <el-table-column align="center" type="selection" width="55"/>
      <el-table-column align="center" label="PK" prop="id"/>
      <el-table-column align="center" label="用户id" prop="userId"/>
      <el-table-column align="center" label="订单单号" prop="orderNo"/>
      <el-table-column align="center" label="支付方式" prop="paymentWay"/>
      <el-table-column align="center" label="是否支付" prop="isPay"/>
      <el-table-column align="center" label="订单名" prop="name"/>
      <el-table-column align="center" label="订单状态" prop="status"/>
      <el-table-column align="center" label="运费金额" prop="freightPrice"/>
      <el-table-column align="center" label="销售金额" prop="salesPrice"/>
      <el-table-column align="center" label="支付金额" prop="paymentPrice"/>
      <el-table-column align="center" label="付款时间" prop="paymentTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.paymentTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="发货时间" prop="deliveryTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deliveryTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="收货时间" prop="receiverTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.receiverTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="成交时间" prop="closingTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.closingTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="买家留言" prop="userMessage"/>
      <el-table-column align="center" label="支付交易ID" prop="transactionId"/>
      <el-table-column align="center" label="物流id" prop="logisticsId"/>
      <el-table-column align="center" label="备注" prop="remark"/>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope">
          <el-button
            @click="handleUpdate(scope.row)"
            icon="el-icon-edit"
            size="mini"
            type="text"
            v-hasPermi="['weixin:info:edit']"
          >修改
          </el-button>
          <el-button
            @click="handleDelete(scope.row)"
            icon="el-icon-delete"
            size="mini"
            type="text"
            v-hasPermi="['weixin:info:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :limit.sync="queryParams.pageSize"
      :page.sync="queryParams.pageNum"
      :total="total"
      @pagination="getList"
      v-show="total>0"
    />

    <!-- 添加或修改订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="500px">
      <el-form :model="form" :rules="rules" label-width="80px" ref="form">
        <el-form-item label="逻辑删除标记" prop="delFlag">
          <el-input placeholder="请输入逻辑删除标记" v-model="form.delFlag"/>
        </el-form-item>
        <el-form-item label="用户id" prop="userId">
          <el-input placeholder="请输入用户id" v-model="form.userId"/>
        </el-form-item>
        <el-form-item label="订单单号" prop="orderNo">
          <el-input placeholder="请输入订单单号" v-model="form.orderNo"/>
        </el-form-item>
        <el-form-item label="支付方式" prop="paymentWay">
          <el-input placeholder="请输入支付方式" v-model="form.paymentWay"/>
        </el-form-item>
        <el-form-item label="是否支付" prop="isPay">
          <el-input placeholder="请输入是否支付" v-model="form.isPay"/>
        </el-form-item>
        <el-form-item label="订单名" prop="name">
          <el-input placeholder="请输入订单名" v-model="form.name"/>
        </el-form-item>
        <el-form-item label="运费金额" prop="freightPrice">
          <el-input placeholder="请输入运费金额" v-model="form.freightPrice"/>
        </el-form-item>
        <el-form-item label="销售金额" prop="salesPrice">
          <el-input placeholder="请输入销售金额" v-model="form.salesPrice"/>
        </el-form-item>
        <el-form-item label="支付金额" prop="paymentPrice">
          <el-input placeholder="请输入支付金额" v-model="form.paymentPrice"/>
        </el-form-item>
        <el-form-item label="付款时间" prop="paymentTime">
          <el-date-picker clearable
                          placeholder="请选择付款时间"
                          type="date"
                          v-model="form.paymentTime"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发货时间" prop="deliveryTime">
          <el-date-picker clearable
                          placeholder="请选择发货时间"
                          type="date"
                          v-model="form.deliveryTime"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="收货时间" prop="receiverTime">
          <el-date-picker clearable
                          placeholder="请选择收货时间"
                          type="date"
                          v-model="form.receiverTime"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="成交时间" prop="closingTime">
          <el-date-picker clearable
                          placeholder="请选择成交时间"
                          type="date"
                          v-model="form.closingTime"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="买家留言" prop="userMessage">
          <el-input placeholder="请输入买家留言" v-model="form.userMessage"/>
        </el-form-item>
        <el-form-item label="支付交易ID" prop="transactionId">
          <el-input placeholder="请输入支付交易ID" v-model="form.transactionId"/>
        </el-form-item>
        <el-form-item label="物流id" prop="logisticsId">
          <el-input placeholder="请输入物流id" v-model="form.logisticsId"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input placeholder="请输入备注" v-model="form.remark"/>
        </el-form-item>
      </el-form>
      <div class="dialog-footer" slot="footer">
        <el-button @click="submitForm" type="primary">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {addInfo, delInfo, getInfo, listInfo, updateInfo} from "@/api/weixin/info";

  export default {
    name: "Info",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 订单表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          userId: null,
          orderNo: null,
          paymentWay: null,
          isPay: null,
          name: null,
          status: null,
          freightPrice: null,
          salesPrice: null,
          paymentPrice: null,
          paymentTime: null,
          deliveryTime: null,
          receiverTime: null,
          closingTime: null,
          userMessage: null,
          transactionId: null,
          logisticsId: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          delFlag: [
            {required: true, message: "逻辑删除标记不能为空", trigger: "blur"}
          ],
          createTime: [
            {required: true, message: "创建时间不能为空", trigger: "blur"}
          ],
          updateTime: [
            {required: true, message: "最后更新时间不能为空", trigger: "blur"}
          ],
          userId: [
            {required: true, message: "用户id不能为空", trigger: "blur"}
          ],
          orderNo: [
            {required: true, message: "订单单号不能为空", trigger: "blur"}
          ],
          paymentWay: [
            {required: true, message: "支付方式不能为空", trigger: "blur"}
          ],
          isPay: [
            {required: true, message: "是否支付不能为空", trigger: "blur"}
          ],
          freightPrice: [
            {required: true, message: "运费金额不能为空", trigger: "blur"}
          ],
          salesPrice: [
            {required: true, message: "销售金额不能为空", trigger: "blur"}
          ],
          paymentPrice: [
            {required: true, message: "支付金额不能为空", trigger: "blur"}
          ],
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询订单列表 */
      getList() {
        this.loading = true;
        listInfo(this.queryParams).then(response => {
          this.infoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          delFlag: null,
          createTime: null,
          updateTime: null,
          userId: null,
          orderNo: null,
          paymentWay: null,
          isPay: null,
          name: null,
          status: "0",
          freightPrice: null,
          salesPrice: null,
          paymentPrice: null,
          paymentTime: null,
          deliveryTime: null,
          receiverTime: null,
          closingTime: null,
          userMessage: null,
          transactionId: null,
          logisticsId: null,
          remark: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加订单";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getInfo(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改订单";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateInfo(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addInfo(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除订单编号为"' + ids + '"的数据项？').then(function () {
          return delInfo(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('weixin/info/export', {
          ...this.queryParams
        }, `info_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
